package com.dinadi.yidi.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.SpecialRequestEntity;
import com.dinadi.yidi.ui.activity.CreativeHotspotActivity;
import com.dinadi.yidi.ui.activity.CreativeProductActivity;
import com.dinadi.yidi.ui.activity.DailyDesignerActivity;
import com.dinadi.yidi.ui.activity.DailyExhibitionActivity;
import com.dinadi.yidi.ui.activity.ExhibitionMatchActivity;
import com.dinadi.yidi.ui.activity.ProductDetailsActivity;
import com.dinadi.yidi.utils.ImageUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * author: JiaYu.He
 * Date: 2017/3/23
 * Time: 12:28
 */

public class SpecialAdapter extends RecyclingPagerAdapter {

    private final List<SpecialRequestEntity> mList;
    private final Context mContext;
    private String type, subjectProductId;

    public SpecialAdapter(Context context) {
        mList = new ArrayList<>();
        mContext = context;
    }

    public void addAll(List<SpecialRequestEntity> list) {
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup container) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.adapter_special_item, null);
            viewHolder.special_title = (TextView) convertView.findViewById(R.id.special_title);
            viewHolder.img_special = (ImageView) convertView.findViewById(R.id.img_special);
            viewHolder.special_content = (TextView) convertView.findViewById(R.id.special_content);
            viewHolder.thematic_type = (LinearLayout) convertView.findViewById(R.id.thematic_type);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.special_title.setText(mList.get(position).getName());
        viewHolder.special_content.setText(mList.get(position).getDesc());
        String imgUrl = mList.get(position).getCoverImg();
        ImageUtils.loadImageView(mContext, imgUrl, viewHolder.img_special);
        viewHolder.thematic_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                type = mList.get(position).getType();
                subjectProductId = mList.get(position).getSubjectId();
                if (type.equals("1")) {
                    /*创意热点*/
                    Intent intent1 = new Intent();
                    intent1.putExtra("subjectProductId", subjectProductId);
                    intent1.setClass(mContext, CreativeHotspotActivity.class);
                    mContext.startActivity(intent1);
                } else if (type.equals("2")) {
                    /*创意产品*/
                    Intent intent1 = new Intent();
                    intent1.putExtra("subjectProductId", subjectProductId);
                    intent1.setClass(mContext, CreativeProductActivity.class);
                    mContext.startActivity(intent1);

                } else if (type.equals("3")) {
                    /*每日设计师*/
                    Intent intent1 = new Intent();
                    intent1.putExtra("subjectProductId", subjectProductId);
                    intent1.setClass(mContext, DailyDesignerActivity.class);
                    mContext.startActivity(intent1);
                } else if (type.equals("4")) {
                    /*每日产品*/
                    Intent intent1 = new Intent();
                    intent1.putExtra("subjectProductId", subjectProductId);
                    intent1.setClass(mContext, ProductDetailsActivity.class);
                    intent1.putExtra("everyday", "0");
                    mContext.startActivity(intent1);
                } else if (type.equals("5")) {
                    /*每日展览*/
                    Intent intent1 = new Intent();
                    intent1.putExtra("subjectProductId", subjectProductId);
                    intent1.setClass(mContext, DailyExhibitionActivity.class);
                    mContext.startActivity(intent1);

                } else if (type.equals("6")) {
                    /*每日展赛*/
                    Intent intent1 = new Intent();
                    intent1.putExtra("subjectProductId", subjectProductId);
                    intent1.putExtra("everydayExhibitionMatch", "0");
                    intent1.setClass(mContext, ExhibitionMatchActivity.class);
                    mContext.startActivity(intent1);
                }
            }

        });


        return convertView;
    }


    class ViewHolder {
        TextView special_title, special_content;
        ImageView img_special;
        LinearLayout thematic_type;
    }

    @Override
    public int getCount() {
        return mList.size();
    }


}

